package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class LibraryService {
    BufferedReader bufferRead;
    BookLibrary bookLibrary;
    MovieLibrary movieLibrary;
    Session session;
    List<String> cmdList = new ArrayList<String>();
    public boolean stop = false;

    public LibraryService(BufferedReader bufferRead, BookLibrary bookLibrary, MovieLibrary movieLibrary, Session session) {
        this.bufferRead = bufferRead;
        this.bookLibrary = bookLibrary;
        this.movieLibrary = movieLibrary;
        this.session = session;
        initCmdList();
    }


    public void initCmdList() {
        cmdList.add("list books");
        cmdList.add("checkout book");
        cmdList.add("return book");
        cmdList.add("list movies");
        cmdList.add("checkout movie");
        cmdList.add("return movie");
        cmdList.add("login");
    }

    public void execute() throws IOException {
        String option = bufferRead.readLine();
        if (option.equalsIgnoreCase(cmdList.get(0))) {
            bookLibrary.display();
        } else if (option.equalsIgnoreCase(cmdList.get(1))) {
            bookLibrary.checkout();
        } else if (option.equalsIgnoreCase(cmdList.get(2))) {
            bookLibrary.returnItem();
        } else if (option.equalsIgnoreCase(cmdList.get(3))) {
            movieLibrary.display();
        } else if (option.equalsIgnoreCase(cmdList.get(4))) {
            movieLibrary.checkout();
        } else if (option.equalsIgnoreCase(cmdList.get(5))) {
            movieLibrary.returnItem();
        }else if (option.equalsIgnoreCase(cmdList.get(6))) {
            session.login();
        }
        else if (option.equalsIgnoreCase("quit")) {
            stop = true;
        } else {
            System.out.println("Select a valid option!");
        }
    }

}
